package com.swinginwind.flexutils.functions
{
	import flash.utils.ByteArray;
	import mx.rpc.xml.SimpleXMLEncoder;
	import flash.xml.XMLDocument;
	import flash.xml.XMLNode;

	/**
	 * @author jimmy
	 * @E-mail: swinginwind@gmail.com
	 * @version 1.0.0
	 * 创建时间：2013-5-14 上午10:06:26
	 * 
	 */
	public class UtilsType
	{
		public function UtilsType()
		{
		}
		
		public static function clone(obj:Object):* 
		{
			var copier:ByteArray = new ByteArray();
			copier.writeObject(obj);
			copier.position = 0;
			return copier.readObject();
		}
		
		public static function objectToXML(obj:Object, root:String):XML {
			if(!root)
				root = "root";
			var qName:QName = new QName(root);
			var xmlDocument:XMLDocument = new XMLDocument();
			var simpleXMLEncoder:SimpleXMLEncoder = new SimpleXMLEncoder(xmlDocument);
			var xmlNode:XMLNode = simpleXMLEncoder.encodeValue(obj, qName, xmlDocument);
			var xml:XML = new XML(xmlDocument.toString());
			// trace(xml.toXMLString());
			return xml;
		}
		
		
		public static function isNumber(ob:*):Boolean
		{
			if(ob == null)
				return false;
			if(ob is Number)
				return true;
			if(ob is String)
			{
				var obStr:String = String(ob);
				if(obStr.length == 0)
					return false;
				if(obStr == ".")
					return false;
				var countDot:int = 0;
				for(var i:uint = 0; i < obStr.length; i++)
				{
					var char:String  = obStr.charAt(i);
					if(char == ".")
					{
						countDot ++;
						continue;
					}
					if(char == "0" || char == "1" || char == "2" || char == "3" || char == "4" || char == "5" || char == "6" || char == "7" || char == "8" || char == "9")
						continue;
					else
						return false;
				}
				if(countDot < 1)
					return true;
			}
			return false;
		}
	}
}